import type { PartialConsult } from '@/types/consult'
import type {
  PayParams,
  OrderListParams,
  OrderList,
  OrderItem,
  AddressItem,
  OrderPre,
  MedicineOrderQuery,
  MedicineOrderDetail,
  MedicineOrderList,
  Logistics
} from '@/types/order'
import http from '@/utils/http'

export function getOrderApi(data: PartialConsult) {
  return http.post<{ id: string }>('/patient/consult/order', data)
}

export function payOrderApi(data: PayParams) {
  return http.post<{ payUrl: string }>('/patient/consult/pay', data)
}

export function payOrderDetailApi(params: { orderId: string }) {
  return http.get<OrderItem>('/patient/consult/order/detail', params)
}

export function getOrderListApi(params: OrderListParams) {
  return http.get<OrderList>('/patient/consult/order/list', params)
}

export function cancelConsultApi(id: string) {
  return http.put(`/patient/order/cancel/${id}`)
}

export function deleteConsultApi(id: string) {
  return http.delete('/patient/order', id)
}

export function getPrescriptionApi(id: string) {
  return http.get(`/patient/consult/prescription/${id}`)
}

// 查询药品订单预支付信息
export const getMedicalOrderPre = (params: { prescriptionId: string }) =>
  http.get<OrderPre>('/patient/medicine/order/pre', params)

// 获取收货地址列表
export const getAddressList = () =>
  http<AddressItem[]>('/patient/order/address')

export const getMedicineOrderIdApi = (data: MedicineOrderQuery) =>
  http.post<{ id: string }>('/patient/medicine/order', data)

export const getMedicineOrderDetailApi = (id: string) =>
  http.get<MedicineOrderDetail>(`/patient/medicine/order/detail/${id}`)

export const getMedicineOrderList = (current: number, status: number) =>
  http.get<MedicineOrderList>(`/patient/medicine/order/mylist`, {
    current,
    pageSize: 5,
    status
  })

// 获取药品订单物流信息
export const getMedicalOrderLogistics = (id: string) =>
  http<Logistics>(`/patient/order/${id}/logistics`)
